import java.util.*;

public class Kapitel
{
  //////////////////////////// fields ////////////////////////
  private ArrayList<Saetning> saetningArrayListWithSaetnings = new ArrayList<Saetning>();
  private int numberOfSaetnings;
  private int lineSize;
  
    ////////////////////////// constructors /////////////////////
  
  public Kapitel()
  {
   lineSize = 90;
    
    numberOfSaetnings = GenerateRandomNumber.generateNumber();
    
    for(int i = 0; i < numberOfSaetnings; i++)
    {
      
      saetningArrayListWithSaetnings.add( new Saetning() );
    }
    
  }
 
  ///////////////////////////// methods ////////////////////////
  
  /** Method to get a particular Saetning
    * @param numberOfSaetning the number of the Saetning which corresponds to the number in the ArrayList
    * @return a Saetning 
   * */
  
  public Saetning getSaetning(int numberOfSaetning)
  {
    return saetningArrayListWithSaetnings.get( numberOfSaetning );
  }
  
  /** Method to get all the Saetnings
    * @return an ArrayList of Saetnings 
   * */
  
  public ArrayList<Saetning> getSaetninger()
  {
    return saetningArrayListWithSaetnings;
  }
  
  /** Method to get the number of Saetnings
    * @return the number of Saetnings 
   * */
  
  public int getAntalSaetninger()
  {
   return numberOfSaetnings;
  }
  
  /** Method to get the linesize used, the linesize defines the maximum length of a Kapitel before paragraph change ocours
    * @return the linesize
    * */
  
  public int getLineSize()
  {
   return lineSize; 
  }
  
  /** Method to get the Kapitel as  a string
    * paragraph change is inserted every time the string is increased by more than lineSize
    * The Saetnings are seperated by ". "
    * */
  
  
  public String toString()
  {
    int lineChangeCounter = 1;
    String returnedString = "";
    
    for(int i = 0; i < saetningArrayListWithSaetnings.size(); i++)
    {
     
      if(returnedString.length() > lineSize * lineChangeCounter)
      {
        if(lineChangeCounter == 1)
        {
          returnedString += "<p>";
          lineChangeCounter++;
        }
        else
        {
          returnedString += "</p><p>";
          lineChangeCounter++;
        }
      }
      
     
         
      if(i == 0)
      {
        returnedString += saetningArrayListWithSaetnings.get(i).toString() + ".";
      }
      else
      {
        if( returnedString.endsWith("\n") )
        {
          returnedString += saetningArrayListWithSaetnings.get(i).toString() + ".";
        }
        else
        {
          returnedString += " " + saetningArrayListWithSaetnings.get(i).toString() + ".";
        }
      }
    }
    
    if(returnedString.length() > lineSize)
    {
      returnedString += "</p>";
    }

    return returnedString;
  }
  

  
  
}

